//
//  ProductAllImageViewController.m
//  FloatClouds
//
//  Created by 黄威 on 16/9/12.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "ProductAllImageViewController.h"
#import "BaseCollectionView.h"
#import "TAMacro.h"
#import "ProductImageCell.h"
#import "UIImageView+WebCache.h"
#import "HeaderView.h"

#import "ProductDetailImage.h"
@interface ProductAllImageViewController ()<UICollectionViewDelegate ,UICollectionViewDataSource>
@property (nonatomic,retain) BaseCollectionView *collectionView;
@property (nonatomic, retain) NSMutableDictionary *dic;
@property (nonatomic, retain) NSArray *arrayOfHeadTitle;

@end
@implementation ProductAllImageViewController


- (void)viewDidLoad{


    
    [self createNavigation];
    self.dic = [NSMutableDictionary dictionary];
    self.arrayOfHeadTitle = @[@"   玻璃纸",@"   六面体",@"   烟支",@"   方位细节",@"   条盒玻璃纸",@"   条盒六面体",@"   条盒防伪细节",@"   创意图片"];
    [self createCollectionView];
    
   

}


- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
//    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(self.view.bounds.size.width *0.8,SCREEN_SIZE_HEIGTH_ME - 34 , self.view.bounds.size.width *0.2 , 30);
//    [button.layer setMasksToBounds:YES];
//    [button.layer setCornerRadius:5.0];
//    button.backgroundColor = [UIColor blackColor];
//    [button setTitle:@"相册" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [self.view addSubview:button];


}

- (void)createNavigation{
    
    //设置navigation相关属性
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:18.0 / 255 green:86.0 / 255 blue:138.0 / 255 alpha:1]];
  
    NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
    
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
     self.navigationItem.title = @"烟品图片";
    
    
}

- (void)createCollectionView{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    //*设置item大小/
    layout.itemSize = CGSizeMake((SCREEN_SIZE_WIDTH_ME / 4.3) , (SCREEN_SIZE_WIDTH_ME / 4.2));
    layout.minimumLineSpacing = 4;
    layout.minimumInteritemSpacing = 4;
    
    layout.sectionInset = UIEdgeInsetsMake(20, 4, 20, 4);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.collectionView = [[BaseCollectionView alloc]initWithFrame:CGRectMake(0 , 64, SCREEN_SIZE_WIDTH_ME , SCREEN_SIZE_HEIGTH_ME - 64) collectionViewLayout:layout];
    
    
  
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = NO;
    
    self.collectionView.backgroundColor = [UIColor colorWithRed:249 green:249 blue:249 alpha:1];
    [self.view addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor blackColor];
    [self.collectionView registerClass:[ProductImageCell class] forCellWithReuseIdentifier:@"Cell"];
    [self.collectionView registerClass:[HeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ProductImageCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];


    cell.backgroundColor = [UIColor blackColor];
    
   NSArray *arrayOfSection = self.arrayOfListPhoto[indexPath.section];
    
    self.dic = arrayOfSection[indexPath.row];
    
    
    
    NSURL *url = [NSURL URLWithString:self.dic[@"thumb"]];
    
    [cell.imageView sd_setImageWithURL:url];
    
    return cell;


}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 8;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    
    NSArray *arrayOfSection = self.arrayOfListPhoto[section];

    return arrayOfSection.count;

}


-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{


    return CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 0.02);

}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
         HeaderView *headView = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
        headView.label.text = self.arrayOfHeadTitle[indexPath.section];
        
         return headView;
    }
    
    return nil;
   
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    ProductDetailImage *ProductDetailImageView = [[ProductDetailImage alloc]init];
    
    
   
    
   ProductDetailImageView.arrayOfListPhoto = self.arrayOfListPhoto;
    
   ProductDetailImageView.indexPath = indexPath;
    
    [self.navigationController pushViewController:ProductDetailImageView animated:YES];
    


}
















































@end
